<?php

class PanelKlientaController extends Zend_Controller_Action {

    public function indexAction() {
     
    }

    //do adaptera przekazuje parametry pobrane z formularza logowania
    public function getAuthAdapter(array $aParams) {

        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $oAuthAdapter = new Zend_Auth_Adapter_DbTable($db, 'user', 'USE_login', 'USE_password');
        $oAuthAdapter->setIdentity($aParams['login']);
        $oAuthAdapter->setCredential($aParams['password']);

        return $oAuthAdapter;
    }

    public function logoutAction() {
        $auth = Zend_Auth::getInstance();
        $auth->clearIdentity();
        $this->_redirect('index');
    }

    public function rejestracjaAction() {

        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {

            $form = new Application_Form_FRejestracja();
            $this->view->rejestracjaForm = $form;

            $request = $this->getRequest();
            $aPost = $this->getRequest()->getPost();
            if ($request->isPost() && $aPost['submit'] == 'ZAREJESTRUJ') {
                if ($form->isValid($request->getPost())) {

                    $user = new Application_Model_DbTable_User();
                    $login = $form->getValue('login');
                    $password = $form->getValue('password');
                    $imie = $form->getValue('imie');
                    $nazwisko = $form->getValue('nazwisko');
                    $email = $form->getValue('email');

                    $user->addUser($login, $password, $imie, $nazwisko, $email);

                    //  return $this->_helper->redirector('index','index');
                }
            }
            $this->view->rejesrtacjaForm = $form;
        } else {
            $this->_redirect('panel-klienta');
        }
    }

}

?>
